import 'package:car_baidu/core/constant/initialize_data.dart';
import 'package:car_baidu/core/model/l_l_user_info_model_entity.dart';
import 'package:car_baidu/core/model/login_info_model.dart';
import 'package:car_baidu/core/service/http_config.dart';
import 'package:car_baidu/core/service/login_request.dart';
import 'package:car_baidu/ui/shared/theme/app_theme.dart';
import 'package:flutter/material.dart';

import '../../shared/px/double_extentsion.dart';
import '../../shared/px/int_extentsion.dart';
import 'mine_list_items.dart';

class LLMineContent extends StatelessWidget {
  const LLMineContent({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      child: Column(
        children: [
          Container(
            height: 186.5.px,
            child: FutureBuilder(
                future: LLLoginRequest.userInfoRequest(
                    LLInitializeData.loginModel!.strPersonID!),
                builder: (ctx, so) {
                  return getUserInfoWiget(context);
                }),
          ),
          Expanded(
            child: ListView.separated(
                itemBuilder: (BuildContext context, int index) {
                  return LLMineListConfig.MineListItems[index];
                },
                separatorBuilder: (BuildContext context, int index) {
                  return Divider(
                    height: 0.5.px,
                    color: Color.fromARGB(255, 233, 233, 233),
                  );
                },
                itemCount: LLMineListConfig.MineListItems.length),
          )
        ],
      ),
      onWillPop: () async {
        return false;
      },
    );
  }

  Widget getUserInfoWiget(BuildContext context) {
    LLUserInfoModelEntity userInfoModel = LLInitializeData.userInfoModel!;
    LLLoginInfoModel loginModel = LLInitializeData.loginModel!;
    String remainDay = loginModel.ServiceDaysRemaining!;
    bool showCharge = false;
    if (remainDay != "新用户") {
      showCharge = true;
    }
    return Stack(
      children: [
        Image.asset(
          "asset/image/mine_top_bg.png",
          fit: BoxFit.cover,
          height: 140.px,
        ),
        Container(
            margin: EdgeInsets.only(top: 31.5.px),
            padding: EdgeInsets.only(left: 16.5.px, right: 12.px),
            child: getHeaderUserInfo(
                context, userInfoModel, loginModel, showCharge)),
        getCenterUserInfo(context, userInfoModel),
      ],
    );
  }

  Widget getHeaderUserInfo(
      BuildContext context,
      LLUserInfoModelEntity userInfoModel,
      LLLoginInfoModel loginModel,
      bool showCharge) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        ClipRRect(
          borderRadius: BorderRadius.circular(52 / 2.px),
          child: FadeInImage(
              width: 52.px,
              height: 52.px,
              placeholder: AssetImage("asset/image/default_user_icon.png"),
              image: NetworkImage(
                  "${HttpConfig.baseUrl}/${userInfoModel.headPicture}")),
        ),
        SizedBox(
          width: 14.px,
        ),
        Expanded(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(
                userInfoModel.nickname!,
                style: LLAppTheme.normalTextStyle.copyWith(color: Colors.white),
              ),
              SizedBox(
                height: 3.px,
              ),
              Text(
                userInfoModel.autograph!,
                style: LLAppTheme.smallTextStyle.copyWith(color: Colors.white),
              ),
              SizedBox(
                height: 3.px,
              ),
              Text(
                loginModel.strPhone!,
                style: LLAppTheme.smallTextStyle.copyWith(color: Colors.white),
              ),
            ],
          ),
        ),
        SizedBox(
          width: 10.px,
        ),
        Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.end,
          children: [
            !showCharge
                ? Text("")
                : Container(
                    width: 43.px,
                    height: 21.px,
                    child: TextButton(
                        style: ButtonStyle(
                          padding: MaterialStateProperty.all(EdgeInsets.all(0)),
                        ),
                        onPressed: () {},
                        child: Stack(
                          alignment: Alignment.center,
                          children: [
                            Image.asset("asset/image/mine_xf_bg.png"),
                            Text(
                              "续费",
                              style: LLAppTheme.smallTextStyle
                                  .copyWith(color: LLAppTheme.primaryColor),
                            ),
                          ],
                        )),
                  ),
            SizedBox(
              height: 4.px,
            ),
            !showCharge
                ? Text(
                    "新用户",
                    style:
                        LLAppTheme.smallTextStyle.copyWith(color: Colors.white),
                  )
                : Text("服务剩余天数:${loginModel.ServiceDaysRemaining}天",
                    style: LLAppTheme.smallTextStyle
                        .copyWith(color: Colors.white)),
          ],
        )
      ],
    );
  }

  Widget getCenterUserInfo(
    BuildContext context,
    LLUserInfoModelEntity userInfoModel,
  ) {
    return Positioned(
        bottom: 3.5.px,
        left: 11.5.px,
        right: 11.5.px,
        child: Container(
          height: 67.5.px,
          decoration: BoxDecoration(
              color: Colors.white, borderRadius: BorderRadius.circular(5)),
          child: Row(
            children: [
              Expanded(
                  child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                    userInfoModel.count!.collectCount.toString(),
                  ),
                  SizedBox(
                    height: 5.5.px,
                  ),
                  Text(
                    "粉丝",
                    style: LLAppTheme.normalTextStyle,
                  )
                ],
              )),
              Container(
                width: 0.5.px,
                alignment: Alignment.center,
                height: 47.px,
                color: Color.fromARGB(255, 229, 229, 229),
              ),
              Expanded(
                  child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(userInfoModel.count!.commentCount.toString()),
                  SizedBox(
                    height: 10.5.px,
                  ),
                  Text(
                    "积分",
                    style: LLAppTheme.normalTextStyle,
                  )
                ],
              )),
              Container(
                width: 0.5.px,
                alignment: Alignment.center,
                height: 47.px,
                color: Color.fromARGB(255, 229, 229, 229),
              ),
              Expanded(
                  child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(userInfoModel.count!.dynamicCount.toString()),
                  SizedBox(
                    height: 10.5.px,
                  ),
                  Text("优惠券", style: LLAppTheme.normalTextStyle),
                ],
              ))
            ],
          ),
        ));
  }
}
